1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci/**
17094332d3Sopenharmony_ci * @addtogroup USB
18094332d3Sopenharmony_ci * @{
19094332d3Sopenharmony_ci *
20094332d3Sopenharmony_ci * @brief Declares USB-related APIs, including the custom data types and functions used to obtain descriptors,
21094332d3Sopenharmony_ci * interface objects, and request objects, and to submit requests.
22094332d3Sopenharmony_ci *
23094332d3Sopenharmony_ci * @since 1.0
24094332d3Sopenharmony_ci * @version 1.0
25094332d3Sopenharmony_ci */
26094332d3Sopenharmony_ci
27094332d3Sopenharmony_ci/**
28094332d3Sopenharmony_ci * @file usb_raw_api.h
29094332d3Sopenharmony_ci *
30094332d3Sopenharmony_ci * @brief Defines the data types and interface functions provided by the USB driver development kit (DDK) in
31094332d3Sopenharmony_ci * expert mode.
32094332d3Sopenharmony_ci *
33094332d3Sopenharmony_ci * @since 1.0
34094332d3Sopenharmony_ci * @version 1.0
35094332d3Sopenharmony_ci */
36094332d3Sopenharmony_ci#ifndef USB_RAW_API_H
37094332d3Sopenharmony_ci#define USB_RAW_API_H
38094332d3Sopenharmony_ci
39094332d3Sopenharmony_ci#include "usb_ddk.h"
40094332d3Sopenharmony_ci#include "usb_session.h"
41094332d3Sopenharmony_ci
42094332d3Sopenharmony_ci#ifdef __cplusplus
43094332d3Sopenharmony_ciextern "C" {
44094332d3Sopenharmony_ci#endif
45094332d3Sopenharmony_ci
46094332d3Sopenharmony_ci/**
47094332d3Sopenharmony_ci * @brief Defines the maximum number of USB interfaces.
48094332d3Sopenharmony_ci */
49094332d3Sopenharmony_ci#define USB_MAXINTERFACES 32
50094332d3Sopenharmony_ci
51094332d3Sopenharmony_ci/**
52094332d3Sopenharmony_ci * @brief Defines a pointer to the USB device handle in expert mode.
53094332d3Sopenharmony_ci */
54094332d3Sopenharmony_citypedef void *UsbRawDevice;
55094332d3Sopenharmony_ci
56094332d3Sopenharmony_ci/**
57094332d3Sopenharmony_ci * @brief Defines a pointer to the USB device operation handle in expert mode.
58094332d3Sopenharmony_ci */
59094332d3Sopenharmony_citypedef void *UsbRawHandle;
60094332d3Sopenharmony_ci
61094332d3Sopenharmony_ci/**
62094332d3Sopenharmony_ci * @brief Defines a pointer to the callback called when a user request in expert mode is complete. This callback
63094332d3Sopenharmony_ci * function is used to fill the <b>#UsbRawFillRequestData</b> object.
64094332d3Sopenharmony_ci */
65094332d3Sopenharmony_citypedef void (*UsbRawRequestCallback)(const void *requestArg);
66094332d3Sopenharmony_ci
67094332d3Sopenharmony_ci/**
68094332d3Sopenharmony_ci * @brief Defines a control request object.
69094332d3Sopenharmony_ci */
70094332d3Sopenharmony_cistruct UsbControlRequestData {
71094332d3Sopenharmony_ci    /** Control request type */
72094332d3Sopenharmony_ci    uint8_t requestType;
73094332d3Sopenharmony_ci    /** Request command */
74094332d3Sopenharmony_ci    uint8_t requestCmd;
75094332d3Sopenharmony_ci    /** Value set based on the request */
76094332d3Sopenharmony_ci    uint16_t value;
77094332d3Sopenharmony_ci    /** Index set based on the request to identify an endpoint or interface */
78094332d3Sopenharmony_ci    uint16_t index;
79094332d3Sopenharmony_ci    /** Length of the transmitted data */
80094332d3Sopenharmony_ci    uint16_t length;
81094332d3Sopenharmony_ci    /** Timeout interval of the control request */
82094332d3Sopenharmony_ci    unsigned int timeout;
83094332d3Sopenharmony_ci    /** Pointer to the transmitted data */
84094332d3Sopenharmony_ci    unsigned char *data;
85094332d3Sopenharmony_ci};
86094332d3Sopenharmony_ci
87094332d3Sopenharmony_ci/**
88094332d3Sopenharmony_ci * @brief Defines request parameters for filling the <b>UsbRawSendBulkRequest</b> or <b>UsbRawSendInterruptRequest</b>
89094332d3Sopenharmony_ci * function.
90094332d3Sopenharmony_ci * Request data to be sent
91094332d3Sopenharmony_ci */
92094332d3Sopenharmony_cistruct UsbRequestData {
93094332d3Sopenharmony_ci    /** Address of the endpoint that sends the request */
94094332d3Sopenharmony_ci    unsigned char endPoint;
95094332d3Sopenharmony_ci    /** Pointer to the request data */
96094332d3Sopenharmony_ci    unsigned char *data;
97094332d3Sopenharmony_ci    /** Length of the request data */
98094332d3Sopenharmony_ci    uint32_t length;
99094332d3Sopenharmony_ci    /** Pointer to the transmitted bytes of the request */
100094332d3Sopenharmony_ci    int32_t *requested;
101094332d3Sopenharmony_ci    /** Request timeout interval */
102094332d3Sopenharmony_ci    unsigned int timeout;
103094332d3Sopenharmony_ci};
104094332d3Sopenharmony_ci
105094332d3Sopenharmony_ci/**
106094332d3Sopenharmony_ci * @brief Defines descriptor parameters in expert mode.
107094332d3Sopenharmony_ci */
108094332d3Sopenharmony_cistruct UsbRawDescriptorParam {
109094332d3Sopenharmony_ci    /** Descriptor type */
110094332d3Sopenharmony_ci    uint8_t descType;
111094332d3Sopenharmony_ci    /** Descriptor index */
112094332d3Sopenharmony_ci    uint8_t descIndex;
113094332d3Sopenharmony_ci    /** Length of the data to read */
114094332d3Sopenharmony_ci    int32_t length;
115094332d3Sopenharmony_ci};
116094332d3Sopenharmony_ci
117094332d3Sopenharmony_ci/**
118094332d3Sopenharmony_ci * @brief Defines a request object in expert mode.
119094332d3Sopenharmony_ci */
120094332d3Sopenharmony_cistruct UsbRawRequest {
121094332d3Sopenharmony_ci    /** Pointer to the data in the buffer */
122094332d3Sopenharmony_ci    unsigned char *buffer;
123094332d3Sopenharmony_ci    /** Length of the user data */
124094332d3Sopenharmony_ci    int32_t length;
125094332d3Sopenharmony_ci    /** Actual length of the data sent at request completion */
126094332d3Sopenharmony_ci    int32_t actualLength;
127094332d3Sopenharmony_ci    /** Request status. For details, see {@link UsbRequestStatus}. */
128094332d3Sopenharmony_ci    UsbRequestStatus status;
129094332d3Sopenharmony_ci    /** Pointer to the user data */
130094332d3Sopenharmony_ci    void *userData;
131094332d3Sopenharmony_ci};
132094332d3Sopenharmony_ci
133094332d3Sopenharmony_ci/**
134094332d3Sopenharmony_ci * @brief Defines a request data object in expert mode.
135094332d3Sopenharmony_ci */
136094332d3Sopenharmony_cistruct UsbRawFillRequestData {
137094332d3Sopenharmony_ci    /** Endpoint of the request data */
138094332d3Sopenharmony_ci    unsigned char endPoint;
139094332d3Sopenharmony_ci    /** Pointer to the request data buffer */
140094332d3Sopenharmony_ci    unsigned char *buffer;
141094332d3Sopenharmony_ci    /** Length of the request data */
142094332d3Sopenharmony_ci    uint32_t length;
143094332d3Sopenharmony_ci    /** Number of transmitted data packets in isochronous transfer */
144094332d3Sopenharmony_ci    int32_t numIsoPackets;
145094332d3Sopenharmony_ci    /** Callback function for request completion on the user side. For details, see {@link UsbRawRequestCallback}. */
146094332d3Sopenharmony_ci    UsbRawRequestCallback callback;
147094332d3Sopenharmony_ci    /** Pointer to the user data */
148094332d3Sopenharmony_ci    void *userData;
149094332d3Sopenharmony_ci    /** Request timeout interval */
150094332d3Sopenharmony_ci    unsigned int timeout;
151094332d3Sopenharmony_ci};
152094332d3Sopenharmony_ci
153094332d3Sopenharmony_ci/**
154094332d3Sopenharmony_ci * @brief Defines the standard USB endpoint descriptor.
155094332d3Sopenharmony_ci */
156094332d3Sopenharmony_cistruct UsbRawEndpointDescriptor {
157094332d3Sopenharmony_ci    /** Standard USB endpoint descriptor */
158094332d3Sopenharmony_ci    struct UsbEndpointDescriptor endpointDescriptor;
159094332d3Sopenharmony_ci    /** Pointer to the extra descriptor */
160094332d3Sopenharmony_ci    const unsigned char *extra;
161094332d3Sopenharmony_ci    /** Length of the extra descriptor, in bytes. The value must be a non-negative number. */
162094332d3Sopenharmony_ci    int32_t extraLength;
163094332d3Sopenharmony_ci};
164094332d3Sopenharmony_ci
165094332d3Sopenharmony_ci/**
166094332d3Sopenharmony_ci * @brief Defines the standard USB interface descriptor.
167094332d3Sopenharmony_ci */
168094332d3Sopenharmony_cistruct UsbRawInterfaceDescriptor {
169094332d3Sopenharmony_ci    /** Standard USB interface descriptor */
170094332d3Sopenharmony_ci    struct UsbInterfaceDescriptor interfaceDescriptor;
171094332d3Sopenharmony_ci    /** Pointer to the endpoint descriptor array */
172094332d3Sopenharmony_ci    const struct UsbRawEndpointDescriptor *endPoint;
173094332d3Sopenharmony_ci    /** Pointer to the extra descriptor */
174094332d3Sopenharmony_ci    const unsigned char *extra;
175094332d3Sopenharmony_ci    /** Length of the extra descriptor, in bytes. The value must be a non-negative number. */
176094332d3Sopenharmony_ci    int32_t extraLength;
177094332d3Sopenharmony_ci};
178094332d3Sopenharmony_ci
179094332d3Sopenharmony_ci/**
180094332d3Sopenharmony_ci * @brief Defines alternate settings for a particular USB interface.
181094332d3Sopenharmony_ci */
182094332d3Sopenharmony_cistruct UsbRawInterface {
183094332d3Sopenharmony_ci    /** Number of alternate settings that belong to the interface. The value must be a non-negative number. */
184094332d3Sopenharmony_ci    uint8_t numAltsetting;
185094332d3Sopenharmony_ci    /** Interface descriptor array. Its length is determined by the numAltsetting field. */
186094332d3Sopenharmony_ci    const struct UsbRawInterfaceDescriptor altsetting[];
187094332d3Sopenharmony_ci};
188094332d3Sopenharmony_ci
189094332d3Sopenharmony_ci/**
190094332d3Sopenharmony_ci * @brief Defines the standard USB configuration descriptor.
191094332d3Sopenharmony_ci */
192094332d3Sopenharmony_cistruct UsbRawConfigDescriptor {
193094332d3Sopenharmony_ci    /** Standard USB configuration descriptor */
194094332d3Sopenharmony_ci    struct UsbConfigDescriptor configDescriptor;
195094332d3Sopenharmony_ci    /** Pointer to the interface array supported by the configuration. The maximum number of interfaces is determined
196094332d3Sopenharmony_ci     * by USB_MAXINTERFACES. */
197094332d3Sopenharmony_ci    const struct UsbRawInterface *interface[USB_MAXINTERFACES];
198094332d3Sopenharmony_ci    /** Pointer to the extra descriptor */
199094332d3Sopenharmony_ci    const unsigned char *extra;
200094332d3Sopenharmony_ci    /** Length of the extra descriptor, in bytes. The value must be a non-negative number. */
201094332d3Sopenharmony_ci    int32_t extraLength;
202094332d3Sopenharmony_ci};
203094332d3Sopenharmony_ci
204094332d3Sopenharmony_ci/**
205094332d3Sopenharmony_ci * @brief Initializes the USB DDK in expert mode.
206094332d3Sopenharmony_ci *
207094332d3Sopenharmony_ci * You can use this function to allocate and initialize resources.
208094332d3Sopenharmony_ci *
209094332d3Sopenharmony_ci * @param session Indicates the pointer to the session context. It can be set to <b>NULL</b> or a value defined in
210094332d3Sopenharmony_ci * {@link UsbSession}.
211094332d3Sopenharmony_ci *
212094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
213094332d3Sopenharmony_ci * otherwise.
214094332d3Sopenharmony_ci */
215094332d3Sopenharmony_ciint32_t UsbRawInit(struct UsbSession **session);
216094332d3Sopenharmony_ci
217094332d3Sopenharmony_ci/**
218094332d3Sopenharmony_ci * @brief Exits the expert mode of the USB DDK.
219094332d3Sopenharmony_ci *
220094332d3Sopenharmony_ci * You can use this function to release occupied resources.
221094332d3Sopenharmony_ci *
222094332d3Sopenharmony_ci * @param session Indicates the pointer to the session context. It can be set to <b>NULL</b> or a value defined in
223094332d3Sopenharmony_ci * {@link UsbSession}.
224094332d3Sopenharmony_ci *
225094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
226094332d3Sopenharmony_ci * otherwise.
227094332d3Sopenharmony_ci */
228094332d3Sopenharmony_ciint32_t UsbRawExit(const struct UsbSession *session);
229094332d3Sopenharmony_ci
230094332d3Sopenharmony_ci/**
231094332d3Sopenharmony_ci * @brief Opens a USB device object.
232094332d3Sopenharmony_ci *
233094332d3Sopenharmony_ci * @param session Indicates the pointer to the session context. It can be set to <b>NULL</b> or a value defined in
234094332d3Sopenharmony_ci * {@link UsbSession}.
235094332d3Sopenharmony_ci * @param busNum Indicates the USB device bus number.
236094332d3Sopenharmony_ci * @param usbAddr Indicates the USB device address.
237094332d3Sopenharmony_ci *
238094332d3Sopenharmony_ci * @return Returns the pointer to the <b>UsbRawHandle</b> if the operation is successful; returns <b>NULL</b>
239094332d3Sopenharmony_ci * otherwise.
240094332d3Sopenharmony_ci */
241094332d3Sopenharmony_ciUsbRawHandle *UsbRawOpenDevice(const struct UsbSession *session, uint8_t busNum, uint8_t usbAddr);
242094332d3Sopenharmony_ci
243094332d3Sopenharmony_ci/**
244094332d3Sopenharmony_ci * @brief Closes a USB device object.
245094332d3Sopenharmony_ci *
246094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
247094332d3Sopenharmony_ci *
248094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
249094332d3Sopenharmony_ci * otherwise.
250094332d3Sopenharmony_ci */
251094332d3Sopenharmony_ciint32_t UsbRawCloseDevice(const UsbRawHandle *devHandle);
252094332d3Sopenharmony_ci
253094332d3Sopenharmony_ci/**
254094332d3Sopenharmony_ci * @brief Performs control transfer.
255094332d3Sopenharmony_ci *
256094332d3Sopenharmony_ci * @param request Indicates the pointer to the request to send.
257094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
258094332d3Sopenharmony_ci * @param requestData Indicates the pointer to the request data to send.
259094332d3Sopenharmony_ci *
260094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
261094332d3Sopenharmony_ci * otherwise.
262094332d3Sopenharmony_ci */
263094332d3Sopenharmony_ciint32_t UsbRawSendControlRequest(const struct UsbRawRequest *request, const UsbRawHandle *devHandle,
264094332d3Sopenharmony_ci    const struct UsbControlRequestData *requestData);
265094332d3Sopenharmony_ci
266094332d3Sopenharmony_ci/**
267094332d3Sopenharmony_ci * @brief Performs bulk transfer.
268094332d3Sopenharmony_ci *
269094332d3Sopenharmony_ci * @param request Indicates the pointer to the request to send.
270094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
271094332d3Sopenharmony_ci * @param requestData Indicates the pointer to the request data to send.
272094332d3Sopenharmony_ci *
273094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
274094332d3Sopenharmony_ci * otherwise.
275094332d3Sopenharmony_ci */
276094332d3Sopenharmony_ciint32_t UsbRawSendBulkRequest(
277094332d3Sopenharmony_ci    const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRequestData *requestData);
278094332d3Sopenharmony_ci/**
279094332d3Sopenharmony_ci * @brief Performs interrupt transfer.
280094332d3Sopenharmony_ci *
281094332d3Sopenharmony_ci * @param request Indicates the pointer to the request to send.
282094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
283094332d3Sopenharmony_ci * @param requestData Indicates the pointer to the request data to send.
284094332d3Sopenharmony_ci *
285094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
286094332d3Sopenharmony_ci * otherwise.
287094332d3Sopenharmony_ci */
288094332d3Sopenharmony_ciint32_t UsbRawSendInterruptRequest(
289094332d3Sopenharmony_ci    const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRequestData *requestData);
290094332d3Sopenharmony_ci
291094332d3Sopenharmony_ci/**
292094332d3Sopenharmony_ci * @brief Obtains the device configuration descriptor based on a specified device ID.
293094332d3Sopenharmony_ci *
294094332d3Sopenharmony_ci * @param rawDev Indicates the pointer to the USB raw device.
295094332d3Sopenharmony_ci * @param configIndex Indicates the ID of the device configuration descriptor.
296094332d3Sopenharmony_ci * @param config Indicates the double pointer to the device configuration descriptor.
297094332d3Sopenharmony_ci *
298094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
299094332d3Sopenharmony_ci * otherwise.
300094332d3Sopenharmony_ci */
301094332d3Sopenharmony_ciint32_t UsbRawGetConfigDescriptor(
302094332d3Sopenharmony_ci    const UsbRawDevice *rawDev, uint8_t configIndex, struct UsbRawConfigDescriptor ** const config);
303094332d3Sopenharmony_ci
304094332d3Sopenharmony_ci/**
305094332d3Sopenharmony_ci * @brief Releases the memory space of the device configuration descriptor.
306094332d3Sopenharmony_ci *
307094332d3Sopenharmony_ci * @param config Indicates the pointer to the device configuration descriptor.
308094332d3Sopenharmony_ci *
309094332d3Sopenharmony_ci */
310094332d3Sopenharmony_civoid UsbRawFreeConfigDescriptor(const struct UsbRawConfigDescriptor *config);
311094332d3Sopenharmony_ci
312094332d3Sopenharmony_ci/**
313094332d3Sopenharmony_ci * @brief Obtains the active device configuration.
314094332d3Sopenharmony_ci *
315094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
316094332d3Sopenharmony_ci * @param config Indicates the pointer to the device configuration descriptor.
317094332d3Sopenharmony_ci *
318094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
319094332d3Sopenharmony_ci * otherwise.
320094332d3Sopenharmony_ci */
321094332d3Sopenharmony_ciint32_t UsbRawGetConfiguration(const UsbRawHandle * const devHandle, int32_t *config);
322094332d3Sopenharmony_ci
323094332d3Sopenharmony_ci/**
324094332d3Sopenharmony_ci * @brief Sets the active device configuration.
325094332d3Sopenharmony_ci *
326094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
327094332d3Sopenharmony_ci * @param config Indicates the device configuration descriptor.
328094332d3Sopenharmony_ci *
329094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
330094332d3Sopenharmony_ci * otherwise.
331094332d3Sopenharmony_ci */
332094332d3Sopenharmony_ciint32_t UsbRawSetConfiguration(const UsbRawHandle *devHandle, int32_t config);
333094332d3Sopenharmony_ci
334094332d3Sopenharmony_ci/**
335094332d3Sopenharmony_ci * @brief Obtains descriptor information.
336094332d3Sopenharmony_ci *
337094332d3Sopenharmony_ci * @param request Indicates the pointer to the request to send.
338094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
339094332d3Sopenharmony_ci * @param param Indicates the pointer to the descriptor parameter. For details, see {@link UsbRawDescriptorParam}.
340094332d3Sopenharmony_ci * @param data Indicates the pointer to the descriptor address.
341094332d3Sopenharmony_ci *
342094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
343094332d3Sopenharmony_ci * otherwise.
344094332d3Sopenharmony_ci */
345094332d3Sopenharmony_ciint32_t UsbRawGetDescriptor(const struct UsbRawRequest *request, const UsbRawHandle *devHandle,
346094332d3Sopenharmony_ci    const struct UsbRawDescriptorParam *param, const unsigned char *data);
347094332d3Sopenharmony_ci
348094332d3Sopenharmony_ci/**
349094332d3Sopenharmony_ci * @brief Obtains the device pointer based on a specified device handle.
350094332d3Sopenharmony_ci *
351094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
352094332d3Sopenharmony_ci *
353094332d3Sopenharmony_ci * @return Returns the device pointer if any; returns <b>NULL</b> otherwise. For details, see {@link UsbRawDevice}.
354094332d3Sopenharmony_ci */
355094332d3Sopenharmony_ciUsbRawDevice *UsbRawGetDevice(const UsbRawHandle * const devHandle);
356094332d3Sopenharmony_ci
357094332d3Sopenharmony_ci/**
358094332d3Sopenharmony_ci * @brief Obtains the USB device descriptor of a specified device.
359094332d3Sopenharmony_ci *
360094332d3Sopenharmony_ci * @param rawDev Indicates the pointer to the USB raw device.
361094332d3Sopenharmony_ci * @param desc Indicates the pointer to the device descriptor.
362094332d3Sopenharmony_ci *
363094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
364094332d3Sopenharmony_ci * otherwise.
365094332d3Sopenharmony_ci */
366094332d3Sopenharmony_ciint32_t UsbRawGetDeviceDescriptor(const UsbRawDevice *rawDev, struct UsbDeviceDescriptor *desc);
367094332d3Sopenharmony_ci
368094332d3Sopenharmony_ci/**
369094332d3Sopenharmony_ci * @brief Declares the interface on the given device handle.
370094332d3Sopenharmony_ci *
371094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle of the interface to declare.
372094332d3Sopenharmony_ci * @param interfaceNumber Indicates the number of the interface to declare.
373094332d3Sopenharmony_ci *
374094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
375094332d3Sopenharmony_ci * otherwise.
376094332d3Sopenharmony_ci */
377094332d3Sopenharmony_ciint32_t UsbRawClaimInterface(const UsbRawHandle *devHandle, int32_t interfaceNumber);
378094332d3Sopenharmony_ci
379094332d3Sopenharmony_ci/**
380094332d3Sopenharmony_ci * @brief Releases the previously declared interface.
381094332d3Sopenharmony_ci *
382094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle of the interface to release.
383094332d3Sopenharmony_ci * @param interfaceNumber Indicates the number of the interface to release.
384094332d3Sopenharmony_ci *
385094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
386094332d3Sopenharmony_ci * otherwise.
387094332d3Sopenharmony_ci */
388094332d3Sopenharmony_ciint32_t UsbRawReleaseInterface(const UsbRawHandle *devHandle, int32_t interfaceNumber);
389094332d3Sopenharmony_ci
390094332d3Sopenharmony_ci/**
391094332d3Sopenharmony_ci * @brief Resets a device.
392094332d3Sopenharmony_ci *
393094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
394094332d3Sopenharmony_ci *
395094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
396094332d3Sopenharmony_ci * otherwise.
397094332d3Sopenharmony_ci */
398094332d3Sopenharmony_ciint32_t UsbRawResetDevice(const UsbRawHandle *devHandle);
399094332d3Sopenharmony_ci
400094332d3Sopenharmony_ci/**
401094332d3Sopenharmony_ci * @brief Allocates a transfer request with a specified number of isochronous transfer packet descriptors.
402094332d3Sopenharmony_ci *
403094332d3Sopenharmony_ci * For details about isochronous transfer, see {@link UsbPipeType}.
404094332d3Sopenharmony_ci *
405094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
406094332d3Sopenharmony_ci * @param isoPackets Indicates the number of isochronous transfer packet descriptors to allocate. The value must be a
407094332d3Sopenharmony_ci * non-negative number.
408094332d3Sopenharmony_ci * @param length Indicates the size of the user space to allocate.
409094332d3Sopenharmony_ci *
410094332d3Sopenharmony_ci * @return Returns the pointer to the <b>UsbHostRequest</b> structure if the operation is successful; returns
411094332d3Sopenharmony_ci * <b>NULL</b> otherwise.
412094332d3Sopenharmony_ci */
413094332d3Sopenharmony_cistruct UsbRawRequest *UsbRawAllocRequest(const UsbRawHandle *devHandle, int32_t isoPackets, int32_t length);
414094332d3Sopenharmony_ci
415094332d3Sopenharmony_ci/**
416094332d3Sopenharmony_ci * @brief Releases the previously allocated transfer request.
417094332d3Sopenharmony_ci *
418094332d3Sopenharmony_ci * @param request Indicates the pointer to the transfer request to release.
419094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
420094332d3Sopenharmony_ci * otherwise.
421094332d3Sopenharmony_ci */
422094332d3Sopenharmony_ciint32_t UsbRawFreeRequest(const struct UsbRawRequest *request);
423094332d3Sopenharmony_ci
424094332d3Sopenharmony_ci/**
425094332d3Sopenharmony_ci * @brief Fills required information in a bulk transfer request.
426094332d3Sopenharmony_ci *
427094332d3Sopenharmony_ci * @param request Indicates the pointer to the request to send.
428094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
429094332d3Sopenharmony_ci * @param fillRequestData Indicates the pointer to the request data to fill.
430094332d3Sopenharmony_ci *
431094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
432094332d3Sopenharmony_ci * otherwise.
433094332d3Sopenharmony_ci */
434094332d3Sopenharmony_ciint32_t UsbRawFillBulkRequest(
435094332d3Sopenharmony_ci    const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRawFillRequestData *fillData);
436094332d3Sopenharmony_ci
437094332d3Sopenharmony_ci/**
438094332d3Sopenharmony_ci * @brief Fills required information in control transfer configuration packets.
439094332d3Sopenharmony_ci *
440094332d3Sopenharmony_ci * @param setup Indicates the pointer to the control information.
441094332d3Sopenharmony_ci * @param requestData Indicates the pointer to the request data to fill.
442094332d3Sopenharmony_ci *
443094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
444094332d3Sopenharmony_ci * otherwise.
445094332d3Sopenharmony_ci */
446094332d3Sopenharmony_ciint32_t UsbRawFillControlSetup(const unsigned char *setup, const struct UsbControlRequestData *requestData);
447094332d3Sopenharmony_ci
448094332d3Sopenharmony_ci/**
449094332d3Sopenharmony_ci * @brief Fills required information in a control transfer request.
450094332d3Sopenharmony_ci *
451094332d3Sopenharmony_ci * @param request Indicates the pointer to the request to send.
452094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
453094332d3Sopenharmony_ci * @param fillRequestData Indicates the pointer to the request data to fill.
454094332d3Sopenharmony_ci *
455094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
456094332d3Sopenharmony_ci * otherwise.
457094332d3Sopenharmony_ci */
458094332d3Sopenharmony_ciint32_t UsbRawFillControlRequest(
459094332d3Sopenharmony_ci    const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRawFillRequestData *fillData);
460094332d3Sopenharmony_ci
461094332d3Sopenharmony_ci/**
462094332d3Sopenharmony_ci * @brief Fills required information in an interrupt transfer request.
463094332d3Sopenharmony_ci *
464094332d3Sopenharmony_ci * @param request Indicates the pointer to the request to send.
465094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
466094332d3Sopenharmony_ci * @param fillRequestData Indicates the pointer to the request data to fill.
467094332d3Sopenharmony_ci *
468094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
469094332d3Sopenharmony_ci * otherwise.
470094332d3Sopenharmony_ci */
471094332d3Sopenharmony_ciint32_t UsbRawFillInterruptRequest(
472094332d3Sopenharmony_ci    const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRawFillRequestData *fillData);
473094332d3Sopenharmony_ci
474094332d3Sopenharmony_ci/**
475094332d3Sopenharmony_ci * @brief Fills required information in an isochronous transfer request.
476094332d3Sopenharmony_ci *
477094332d3Sopenharmony_ci * @param request Indicates the pointer to the request to send.
478094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
479094332d3Sopenharmony_ci * @param fillRequestData Indicates the pointer to the request data to fill.
480094332d3Sopenharmony_ci *
481094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
482094332d3Sopenharmony_ci * otherwise.
483094332d3Sopenharmony_ci */
484094332d3Sopenharmony_ciint32_t UsbRawFillIsoRequest(
485094332d3Sopenharmony_ci    const struct UsbRawRequest *request, const UsbRawHandle *devHandle, const struct UsbRawFillRequestData *fillData);
486094332d3Sopenharmony_ci
487094332d3Sopenharmony_ci/**
488094332d3Sopenharmony_ci * @brief Submits a transfer request.
489094332d3Sopenharmony_ci *
490094332d3Sopenharmony_ci * @param request Indicates the pointer to the request to submit.
491094332d3Sopenharmony_ci *
492094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
493094332d3Sopenharmony_ci * otherwise.
494094332d3Sopenharmony_ci */
495094332d3Sopenharmony_ciint32_t UsbRawSubmitRequest(const struct UsbRawRequest *request);
496094332d3Sopenharmony_ci
497094332d3Sopenharmony_ci/**
498094332d3Sopenharmony_ci * @brief Cancels a transfer request.
499094332d3Sopenharmony_ci *
500094332d3Sopenharmony_ci * @param request Indicates the pointer to the request to cancel.
501094332d3Sopenharmony_ci *
502094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
503094332d3Sopenharmony_ci * otherwise.
504094332d3Sopenharmony_ci */
505094332d3Sopenharmony_ciint32_t UsbRawCancelRequest(const struct UsbRawRequest *request);
506094332d3Sopenharmony_ci
507094332d3Sopenharmony_ci/**
508094332d3Sopenharmony_ci * @brief Defines the handle for a transfer request event.
509094332d3Sopenharmony_ci *
510094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
511094332d3Sopenharmony_ci *
512094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
513094332d3Sopenharmony_ci * otherwise.
514094332d3Sopenharmony_ci */
515094332d3Sopenharmony_ciint32_t UsbRawHandleRequests(const UsbRawHandle *devHandle);
516094332d3Sopenharmony_ciint32_t GetRawConfigDescriptor(
517094332d3Sopenharmony_ci    const UsbRawHandle *rawHandle, uint8_t configIndex, uint8_t *configDesc, uint32_t configDescLen);
518094332d3Sopenharmony_ci
519094332d3Sopenharmony_ci/**
520094332d3Sopenharmony_ci * @brief Defines the handle for a control msg.
521094332d3Sopenharmony_ci *
522094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
523094332d3Sopenharmony_ci *
524094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value defined in {@link HDF_STATUS}
525094332d3Sopenharmony_ci * otherwise.
526094332d3Sopenharmony_ci */
527094332d3Sopenharmony_ciint32_t UsbRawControlMsg(const UsbRawHandle * const devHandle, struct UsbControlRequestData *ctrlData);
528094332d3Sopenharmony_ci
529094332d3Sopenharmony_ci/**
530094332d3Sopenharmony_ci * @brief Defines the handle for get usb speed information.
531094332d3Sopenharmony_ci *
532094332d3Sopenharmony_ci * @param devHandle Indicates the pointer to the device handle.
533094332d3Sopenharmony_ci *
534094332d3Sopenharmony_ci * @return Returns speed enum value defined in {@link UsbnetHostDeviceSpeed}
535094332d3Sopenharmony_ci * otherwise.
536094332d3Sopenharmony_ci */
537094332d3Sopenharmony_ciint32_t UsbRawGetUsbSpeed(const UsbRawHandle * const devHandle);
538094332d3Sopenharmony_ci
539094332d3Sopenharmony_ci#ifdef __cplusplus
540094332d3Sopenharmony_ci}
541094332d3Sopenharmony_ci#endif
542094332d3Sopenharmony_ci
543094332d3Sopenharmony_ci#endif /* USB_RAW_API_H */
544094332d3Sopenharmony_ci/** @} */
545