The template is used to generate nodes with consistent syntax, thereby facilitating the traverse and management of nodes of the same type.
The template is used to generate nodes with consistent syntax, thereby facilitating the traverse and management of nodes of the same type.
If a node is defined using the keyword **template**, its child nodes inherit from the node configuration through the double colon operator (::). The child nodes can modify but cannot add or delete attributes in **template**. The attributes not defined in the child nodes will use the attributes defined in **template** as the default values.
If a node is defined using the keyword **template**, its child nodes inherit from the node configuration through the double colon operator (::). The child nodes can modify or add but cannot delete attributes in **template**. The attributes not defined in the child nodes will use the attributes defined in **template** as the default values.
USB host development aims to provide host-related functions, including protocol encapsulation, device management, and driver installation and uninstall.
USB host development aims to provide host-related functions, including protocol encapsulation, device management, and driver installation and uninstall.
USB device development aims to provide device-related functions, including device management, configuration management, and I/O management. These functions implement creation, configuration, and data communication of USB devices.
USB device development aims to provide device-related functions, including device management, configuration management, and I/O management. These functions implement creation, configuration, and data communication of USB devices.
The following figures show the UBS host and device driver models.
The following figures show the USB host and device driver models.
**Figure 1** USB host driver model<aname="fig1649563542917"></a>
- The USB host Driver Development Kit (DDK) provides driver capability APIs that can be directly called in user mode. The APIs can be classified into the DDK initialization class, interface operation class, and request operation class by function. These APIs can be used to perform DDK initialization, bind/release and open/close an interface, allocate/release a request, and implement synchronous or asynchronous transfer.
- The USB host Driver Development Kit (DDK) provides driver capability APIs that can be directly called in user mode. The APIs can be classified into the DDK initialization class, interface operation class, and request operation class by function. These APIs can be used to perform DDK initialization, bind/release and open/close an interface, allocate/release a request, and implement synchronous or asynchronous transfer.
- The USB device DDK provides device management, I/O management, and configuration management APIs, which can be used to create and delete a device, obtain/open an interface, and perform synchronous or asynchronous transfer.
- The USB device DDK provides device management, I/O management, and configuration management APIs, which can be used to create or delete a device, obtain or open an interface, and perform synchronous or asynchronous transfer.
### Available APIs(<a name="section141mcpsimp"></a>)
[Figure 1](#fig1649563542917) describes the APIs provided by the USB host driver model.
### Available APIs
**Table 1** APIs provided by the USB host driver model
The tables below describe the APIs provided by the USB host driver model.
| int32_t UsbExitHostSdk(const struct UsbSession<br>\*session); | Exits the USB host driver DDK.|
</th>
| const struct UsbInterface \*UsbClaimInterface(const<br>struct UsbSession \*session, uint8_t busNum, uint8_t<br>usbAddr, uint8_t interfaceIndex); | Obtains a USB interface.|
</tr>
| int UsbReleaseInterface(const struct UsbInterface<br>\*interfaceObj); | Releases a USB interface.|
</thead>
| int UsbAddOrRemoveInterface(const struct UsbSession<br>\*session, uint8_t busNum, uint8_t usbAddr, uint8_t<br>interfaceIndex, UsbInterfaceStatus status); | Adds or removes a USB interface.|
| int32_t UsbSelectInterfaceSetting(const<br>UsbInterfaceHandle \*interfaceHandle, uint8_t<br>settingIndex, struct UsbInterface \*\*interfaceObj); | Sets a USB interface.|
</td>
| int32_t UsbGetPipeInfo(const UsbInterfaceHandle<br>\*interfaceHandle, uint8_t settingIndex, uint8_t pipeId,<br>struct UsbPipeInfo \*pipeInfo); | Obtains USB pipe information.|
<tdclass="cellrowborder"valign="top"width="33.33333333333333%"headers="mcps1.2.4.1.3 "><pid="p27252992712"><aname="p27252992712"></a><aname="p27252992712"></a>Initializes the USB host driver DDK.</p>
| int32_t UsbClearInterfaceHalt(const<br>UsbInterfaceHandle \*interfaceHandle, uint8_t<br>pipeAddress); | Clears the state of the pipe with the specified index.|
</td>
| struct UsbRequest \*UsbAllocRequest(const<br>UsbInterfaceHandle \*interfaceHandle, int isoPackets<br>, int length); | Allocates a request object.|
</tr>
| int UsbFreeRequest(const struct UsbRequest<br>\*request); | Releases a request object.|
| int UsbSubmitRequestAsync(const struct UsbRequest<br>\*request); | Sends an asynchronous request.|
</td>
| int32_t UsbFillRequest(const struct UsbRequest<br>\*request, const UsbInterfaceHandle \*interfaceHandle,<br>const struct UsbRequestParams \*params); | Fills in a request.|
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p172549192711"><aname="p172549192711"></a><aname="p172549192711"></a>Exits the USB host driver DDK.</p>
| sint UsbCancelRequest(const struct UsbRequest<br>\*request); | Cancels an asynchronous request.|
</td>
| int UsbSubmitRequestSync(const struct UsbRequest<br>\*request); | Sends a synchronous request.|
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p187255962716"><aname="p187255962716"></a><aname="p187255962716"></a>Obtains a USB interface.</p>
| API| Description|
</td>
| -------- | -------- |
</tr>
| int UsbRawInit(struct UsbSession \*\*session); | Initializes the USB raw APIs.|
| int UsbRawExit(const struct UsbSession \*session); | Exits the USB raw APIs.|
</td>
| UsbRawHandle \*UsbRawOpenDevice(const struct<br>UsbSession \*session, uint8_t busNum, uint8_t<br>usbAddr); | Opens a USB device.|
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p117251894270"><aname="p117251894270"></a><aname="p117251894270"></a>Releases a USB interface.</p>
| int UsbRawCloseDevice(const UsbRawHandle<br>\*devHandle); | Closes a USB device.|
</td>
| int UsbRawSendControlRequest(const struct<br>UsbRawRequest \*request, const UsbRawHandle<br>\*devHandle, const struct UsbControlRequestData<br>\*requestData); | Performs a control transfer synchronously.|
</tr>
| int UsbRawSendBulkRequest(const struct<br>UsbRawRequest \*request, const UsbRawHandle<br>\*devHandle, const struct UsbRequestData<br>\*requestData); | Performs a bulk transfer synchronously.|
| int UsbRawSendInterruptRequest(const struct<br>UsbRawRequest \*request, const UsbRawHandle<br>\*devHandle, const struct UsbRequestData<br>\*requestData); | Performs an interrupt transfer synchronously.|
</td>
| int UsbRawGetConfigDescriptor(const UsbRawDevice<br>\*rawDev, uint8_t configIndex, struct<br>UsbRawConfigDescriptor \*\*config); | Obtains the configuration descriptor of a device.|
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p157251914278"><aname="p157251914278"></a><aname="p157251914278"></a>Adds or removes a USB interface.</p>
| void UsbRawFreeConfigDescriptor(const struct<br>UsbRawConfigDescriptor \*config); | Releases the memory space of a configuration descriptor.|
</td>
| int UsbRawGetConfiguration(const UsbRawHandle<br>\*devHandle, int \*config); | Obtains the configuration in use.|
</tr>
| int UsbRawSetConfiguration(const UsbRawHandle<br>\*devHandle, int config); | Sets the configuration in use.|
| UsbRawDevice \*UsbRawGetDevice(const UsbRawHandle<br>\*devHandle); | Obtains the device pointer based on the device handle.|
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p67254915272"><aname="p67254915272"></a><aname="p67254915272"></a>Opens a USB interface.</p>
| int UsbRawGetDeviceDescriptor(const UsbRawDevice<br>\*rawDev, struct<br>UsbDeviceDescriptor \*desc); | Obtains the device descriptor of the specified USB device.|
</td>
| int UsbRawClaimInterface(const UsbRawHandle<br>\*devHandle, int<br>interfaceNumber); | Declares the interface on the specified device handle.|
</tr>
| int UsbRawReleaseInterface(const UsbRawHandle<br>\*devHandle, in<br>t interfaceNumber); | Releases the previously declared interface.|
| int UsbRawResetDevice(const UsbRawHandle<br>\*devHandle); | Resets a device.|
</td>
| struct UsbRawRequest \*UsbRawAllocRequest(const<br>UsbRawHandle<br>\*devHandle, int isoPackets, int length); | Allocates a transfer request with the specified number of sync packet descriptors.|
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p67251095276"><aname="p67251095276"></a><aname="p67251095276"></a>Closes a USB interface.</p>
| int UsbRawFreeRequest(const struct UsbRawRequest<br>\*request); | Releases the previously allocated transfer request.|
</td>
| int UsbRawFillBulkRequest(const struct UsbRawRequest<br>\*request, const UsbRawHandle \*devHandle, const struct<br>UsbRawFillRequestData \*fillData); | Fills in a bulk transfer request.|
</tr>
| int UsbRawFillControlSetup(const unsigned char \*setup,<br>const struct UsbControlRequestData \*requestData); | Fills in a control setup packet.|
| int UsbRawFillControlRequest(const struct UsbRawRequest<br>\*request, const UsbRawHandle \*devHandle, const struct<br>UsbRawFillRequestData \*fillData); | Fills in a control transfer request.|
</td>
| int UsbRawFillInterruptRequest(const struct UsbRawRequest<br>\*request, const UsbRawHandle \*devHandle, const struct<br>UsbRawFillRequestData \*fillData); | Fills in an interrupt transfer request.|
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p6725109112720"><aname="p6725109112720"></a><aname="p6725109112720"></a>Sets a USB interface.</p>
| int UsbRawFillIsoRequest(const struct UsbRawRequest<br>\*request, const UsbRawHandle \*devHandle, const struct<br>UsbRawFillRequestData \*fillData); | Fills in an isochronous transfer request.|
</td>
| int UsbRawSubmitRequest(const struct UsbRawRequest<br>\*request); | Submits a transfer request.|
</tr>
| int UsbRawCancelRequest(const struct UsbRawRequest<br>\*request); | Cancels a transfer request.|
| int UsbRawHandleRequests(const UsbRawHandle<br>\*devHandle); | Handles a transfer request event.|
</td>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p107261298272"><aname="p107261298272"></a><aname="p107261298272"></a>Obtains USB pipe information.</p>
The tables below describe the APIs provided by the USB device driver model.
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p177261797274"><aname="p177261797274"></a><aname="p177261797274"></a>Clears the state of the pipe with the specified index.</p>
| -------- | -------- |
</td>
| const struct UsbFnDevice \*UsbFnCreateDevice(const<br>char \*udcName, const struct UsbFnDescriptorData<br>\*descriptor); | Creates a USB device.|
</tr>
| int UsbFnRemoveDevice(struct UsbFnDevice<br>\*fnDevice); | Deletes a USB device.|
<trid="row1757189172714"><tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.1 "><pid="p1726998273"><aname="p1726998273"></a><aname="p1726998273"></a>struct UsbRequest *UsbAllocRequest(const UsbInterfaceHandle *interfaceHandle, int isoPackets, int length);</p>
| const struct UsbFnDevice \*UsbFnGetDevice(const char<br>\*udcName); | Obtains a USB device.|
</td>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p1272617982713"><aname="p1272617982713"></a><aname="p1272617982713"></a>Allocates a request object.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p177271592271"><aname="p177271592271"></a><aname="p177271592271"></a>Releases a request object.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p372714942718"><aname="p372714942718"></a><aname="p372714942718"></a>Sends an asynchronous request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p872713910270"><aname="p872713910270"></a><aname="p872713910270"></a>Fills in a request.</p>
| struct UsbFnRequest<br>\*UsbFnAllocCtrlRequest(UsbFnInterfaceHandle handle,<br>uint32_t len); | Allocates a control transfer request.|
</td>
| struct UsbFnRequest \*UsbFnAllocRequest(UsbFnInterfaceHandle handle,<br>uint8_t pipe, uint32_t len); | Allocates a data request.|
</tr>
| int UsbFnFreeRequest(struct UsbFnRequest \*req); | Releases a request.|
| int UsbFnSubmitRequestAsync(struct UsbFnRequest<br>\*req); | Sends an asynchronous request.|
</td>
| int UsbFnSubmitRequestSync(struct UsbFnRequest<br>\*req, uint32_t timeout); | Sends a synchronous request.|
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p37271897276"><aname="p37271897276"></a><aname="p37271897276"></a>Cancels an asynchronous request.</p>
| int UsbFnCancelRequest(struct UsbFnRequest \*req); | Cancels a request.|
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p87279914277"><aname="p87279914277"></a><aname="p87279914277"></a>Sends a synchronous request.</p>
<tdclass="cellrowborder"valign="top"width="33.33333333333333%"headers="mcps1.2.4.1.3 "><pid="p1572711919272"><aname="p1572711919272"></a><aname="p1572711919272"></a>Initializes the USB raw APIs.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p372710942717"><aname="p372710942717"></a><aname="p372710942717"></a>Exits the USB raw APIs.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p1772719972717"><aname="p1772719972717"></a><aname="p1772719972717"></a>Opens a USB device.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p1372715902711"><aname="p1372715902711"></a><aname="p1372715902711"></a>Closes a USB device.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p272715932717"><aname="p272715932717"></a><aname="p272715932717"></a>Performs a control transfer synchronously.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p872789162713"><aname="p872789162713"></a><aname="p872789162713"></a>Performs a bulk transfer synchronously.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p117271895271"><aname="p117271895271"></a><aname="p117271895271"></a>Performs an interrupt transfer synchronously.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p472714912710"><aname="p472714912710"></a><aname="p472714912710"></a>Obtains the configuration descriptor of a device.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p772759162711"><aname="p772759162711"></a><aname="p772759162711"></a>Releases the memory space of a configuration descriptor.</p>
</td>
</tr>
<trid="row9756119182711"><tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.1 "><pid="p3727699274"><aname="p3727699274"></a><aname="p3727699274"></a>int UsbRawGetConfiguration(const UsbRawHandle *devHandle, int *config);</p>
</td>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p13728109192717"><aname="p13728109192717"></a><aname="p13728109192717"></a>Obtains the configuration in use.</p>
</td>
</tr>
<trid="row37567922714"><tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.1 "><pid="p1872849162718"><aname="p1872849162718"></a><aname="p1872849162718"></a>int UsbRawSetConfiguration(const UsbRawHandle *devHandle, int config);</p>
</td>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p87280914277"><aname="p87280914277"></a><aname="p87280914277"></a>Sets the configuration in use.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p472879202719"><aname="p472879202719"></a><aname="p472879202719"></a>Obtains the device pointer based on the device handle.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p8728139172715"><aname="p8728139172715"></a><aname="p8728139172715"></a>Obtains the device descriptor of the specified USB device.</p>
</td>
</tr>
<trid="row117561919273"><tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.1 "><pid="p072820912714"><aname="p072820912714"></a><aname="p072820912714"></a>int UsbRawClaimInterface(const UsbRawHandle *devHandle, int interfaceNumber);</p>
</td>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p972817914279"><aname="p972817914279"></a><aname="p972817914279"></a>Declares the interface on the specified device handle.</p>
</td>
</tr>
<trid="row87561920275"><tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.1 "><pid="p2728191276"><aname="p2728191276"></a><aname="p2728191276"></a>int UsbRawReleaseInterface(const UsbRawHandle *devHandle, int interfaceNumber);</p>
</td>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p8728159102710"><aname="p8728159102710"></a><aname="p8728159102710"></a>Releases the previously declared interface.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p107281992272"><aname="p107281992272"></a><aname="p107281992272"></a>Resets a device.</p>
</td>
</tr>
<trid="row14756109152719"><tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.1 "><pid="p137288914273"><aname="p137288914273"></a><aname="p137288914273"></a>struct UsbRawRequest *UsbRawAllocRequest(const UsbRawHandle *devHandle, int isoPackets, int length);</p>
</td>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p27281797274"><aname="p27281797274"></a><aname="p27281797274"></a>Allocates a transfer request with the specified number of sync packet descriptors.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p17281917278"><aname="p17281917278"></a><aname="p17281917278"></a>Releases the previously allocated transfer request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p117281090271"><aname="p117281090271"></a><aname="p117281090271"></a>Fills in a bulk transfer request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p177281299278"><aname="p177281299278"></a><aname="p177281299278"></a>Fills in a control setup packet.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p1372815952715"><aname="p1372815952715"></a><aname="p1372815952715"></a>Fills in a control transfer request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p19728092271"><aname="p19728092271"></a><aname="p19728092271"></a>Fills in an interrupt transfer request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p107281913275"><aname="p107281913275"></a><aname="p107281913275"></a>Fills in an isochronous transfer request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p187299922718"><aname="p187299922718"></a><aname="p187299922718"></a>Submits a transfer request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p872912911274"><aname="p872912911274"></a><aname="p872912911274"></a>Cancels a transfer request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p572929102710"><aname="p572929102710"></a><aname="p572929102710"></a>Handles a transfer request event.</p>
</td>
</tr>
</tbody>
</table>
[Figure 2](#fig8847615103013) describes the APIs provided by the USB device driver model.
**Table 2** APIs provided by the USB device driver model
<tdclass="cellrowborder"valign="top"width="33.33333333333333%"headers="mcps1.2.4.1.3 "><pid="p241853152716"><aname="p241853152716"></a><aname="p241853152716"></a>Creates a USB device.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p5435318271"><aname="p5435318271"></a><aname="p5435318271"></a>Deletes a USB device.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p54135392719"><aname="p54135392719"></a><aname="p54135392719"></a>Obtains a USB device.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p124453132715"><aname="p124453132715"></a><aname="p124453132715"></a>Closes an interface.</p>
<tdclass="cellrowborder"valign="top"width="33.33333333333333%"headers="mcps1.2.4.1.3 "><pid="p5514538278"><aname="p5514538278"></a><aname="p5514538278"></a>Applies for a control transfer request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p105105342716"><aname="p105105342716"></a><aname="p105105342716"></a>Applies for a data request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p26165372718"><aname="p26165372718"></a><aname="p26165372718"></a>Releases a request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p361253112718"><aname="p361253112718"></a><aname="p361253112718"></a>Sends an asynchronous request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p06853112710"><aname="p06853112710"></a><aname="p06853112710"></a>Sends a synchronous request.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p13725312275"><aname="p13725312275"></a><aname="p13725312275"></a>Cancels a request.</p>
</td>
</tr>
</tbody>
</table>
## Development Guidelines<a name="section581mcpsimp"></a>
The USB driver is developed based on the Hardware Driver Foundation (HDF), platform, and Operating System Abstraction Layer (OSAL) APIs. A unified driver model is provided for USB devices, irrespective of the operating system and chip architecture. This document uses a serial port as an example to describe how to develop drivers for the USB host and USB device.
The USB driver is developed based on the Hardware Driver Foundation (HDF), platform, and Operating System Abstraction Layer (OSAL) APIs. A unified driver model is provided for USB devices, irrespective of the operating system and chip architecture. This document uses a serial port as an example to describe how to develop drivers for the USB host and USB device.
### How to Develop<a name="section583mcpsimp"></a>
### Developing Driver Using Host DDK APIs<a name="section584mcpsimp"></a>
### Developing Driver Using Host DDK APIs
1. Configure the driver mapping table.
2. Initialize the USB host DDK.
3. Obtain a **UsbInterface** object.
4. Open the **UsbInterface** object to obtain the **UsbInterfaceHandle** object.
5. Obtain pipe information of the specified **pipeIndex** based on the **UsbInterfaceHandle** object.
6. Allocate an I/O request for the **UsbInterfaceHandle** object.
7. Fill in the I/O request based on the input parameters.
8. Submit the I/O request in synchronous or asynchronous mode.
### Developing Driver Using Host Raw APIs
1. Configure the driver mapping table.
1. Configure the driver mapping table.
2. Initialize the USB host DDK.
3. Obtain a **UsbInterface** object.
4. Open the **UsbInterface** object to obtain the **UsbInterfaceHandle** object.
5. Obtain pipe information of the specified **pipeIndex** based on the **UsbInterfaceHandle** object.
6. Allocate an I/O request for the **UsbInterfaceHandle** object.
7. Fill in the I/O request based on the input parameters.
8. Submit the I/O request in synchronous or asynchronous mode.
### Developing Driver Using Host Raw APIs<a name="section594mcpsimp"></a>
2. Initialize the host raw data, open the USB device, obtain the descriptor, and then obtain interface and endpoint information based on the descriptor.
1. Configure the driver mapping table.
3. Allocate a request and fill in the request based on the transfer type.
2. Initialize the host raw data, open the USB device, obtain the descriptor, and then obtain interface and endpoint information based on the descriptor.
3. Allocate a request and fill in the request based on the transfer type.
4. Submit the I/O request in synchronous or asynchronous mode.
### Developing Driver Using Device DDK APIs<a name="section600mcpsimp"></a>
4. Submit the I/O request in synchronous or asynchronous mode.
1. Construct a descriptor.
2. Instantiate a USB device using the descriptor constructed.
3. Call **UsbFnDeviceGetInterface** to obtain an interface, call **UsbFnInterfaceGetPipeInfo** to obtain pipe information based on the interface, call **UsbFnInterfaceOpen** to open the interface to obtain the handle, and call **UsbFnRequestAlloc** to obtain the request based on the handle and pipe ID.
4. Call **UsbFnInterfaceStartRecvEvent** to receive events such as Enable and Setup, and respond to the events in **UsbFnEventCallback**.
5. Send and receive data in synchronous or asynchronous mode.
## Development Examples<a name="section607mcpsimp"></a>
### Developing Driver Using Device DDK APIs
1. Construct a descriptor.
2. Instantiate a USB device using the descriptor constructed.
3. Call **UsbFnDeviceGetInterface** to obtain an interface, call **UsbFnInterfaceGetPipeInfo** to obtain pipe information based on the interface, call **UsbFnInterfaceOpen** to open the interface to obtain the handle, and call **UsbFnRequestAlloc** to obtain the request based on the handle and pipe ID.
4. Call **UsbFnInterfaceStartRecvEvent** to receive events such as Enable and Setup, and respond to the events in **UsbFnEventCallback**.
5. Send and receive data in synchronous or asynchronous mode.
## Development Example
The following examples help you better understand the development of the USB serial port driver.
The following examples help you better understand the development of the USB serial port driver.
### Developing Driver Using Host DDK APIs<a name="section609mcpsimp"></a>
### Developing Driver Using Host DDK APIs
```
```
root {
root {
module = "usb_pnp_device";
module = "usb_pnp_device";
...
@@ -431,7 +210,7 @@ root {
...
@@ -431,7 +210,7 @@ root {
interfaceClass = [0];
interfaceClass = [0];
// Interface subtype. You can enter multiple subtypes as needed.
// Interface subtype. You can enter multiple subtypes as needed.
interfaceSubClass = [2, 0];
interfaceSubClass = [2, 0];
// Protocol that the interface complies with. You can enter multiple protocols as needed.
// Protocol that the interface complies with. You can enter multiple protocols as needed.
interfaceProtocol = [1, 2];
interfaceProtocol = [1, 2];
// Interface number. You can enter multiple interface numbers as needed.
// Interface number. You can enter multiple interface numbers as needed.
### Developing Driver Using Device DDK APIs<a name="section615mcpsimp"></a>
The core code of the USB Abstract Control Model (ACM) device is available in **drivers/peripheral/usb/gadget/function/acm/cdcacm.c**. The following is an example:
### Developing Driver Using Device DDK APIs
The core code of the USB Abstract Control Model (ACM) device is available in **drivers\peripheral\usb\gadget\function\acm\cdcacm.c**. The following is an example.