1# IUsbDdk 2 3 4## 概述 5 6声明USB主机用于访问USB设备的USB DDK API。 7 8上层USB服务调用相关功能接口,可以打开/关闭设备,获取设备描述符,批量读取/写入数据等。 9 10**起始版本:** 4.0 11 12**相关模块:**[HdiUsbDdk](_hdi_usb_ddk.md) 13 14 15## 汇总 16 17 18### Public 成员函数 19 20| 名称 | 描述 | 21| -------- | -------- | 22| [Init](#init) () | 初始化DDK。 | 23| [Release](#release) () | 在停止数据传输后关闭占用的USB设备接口,并释放相关资源。 | 24| [GetDeviceDescriptor](#getdevicedescriptor) ([in] unsigned long deviceId, [out] struct [UsbDeviceDescriptor](_usb_device_descriptor.md) desc) | 获取USB设备描述符。 | 25| [GetConfigDescriptor](#getconfigdescriptor) ([in] unsigned long deviceId, [in] unsigned char configIndex, [out] List< unsigned char > configDesc) | 获取配置描述符。 | 26| [ClaimInterface](#claiminterface) ([in] unsigned long deviceId, [in] unsigned char interfaceIndex, [out] unsigned long interfaceHandle) | 声明USB接口。 | 27| [ReleaseInterface](#releaseinterface) ([in] unsigned long interfaceHandle) | 在停止数据传输后关闭占用的USB设备接口,并释放相关资源。 | 28| [SelectInterfaceSetting](#selectinterfacesetting) ([in] unsigned long interfaceHandle, [in] unsigned char settingIndex) | 激活USB接口的备用设置。 | 29| [GetCurrentInterfaceSetting](#getcurrentinterfacesetting) ([in] unsigned long interfaceHandle, [out] unsigned char settingIndex) | 获取USB接口的激活备用设置。 | 30| [SendControlReadRequest](#sendcontrolreadrequest) ([in] unsigned long interfaceHandle, [in] struct [UsbControlRequestSetup](_usb_control_request_setup.md) setup, [in] unsigned int timeout, [out] List< unsigned char > data) | 发送控制读取传输请求。此API以同步方式工作。 | 31| [SendControlWriteRequest](#sendcontrolwriterequest) ([in] unsigned long interfaceHandle, [in] struct [UsbControlRequestSetup](_usb_control_request_setup.md) setup, [in] unsigned int timeout, [in] List< unsigned char > data) | 发送控制写入传输请求。此API以同步方式工作。 | 32| [SendPipeRequest](#sendpiperequest) ([in] struct [UsbRequestPipe](_usb_request_pipe.md) pipe, [in] unsigned int size, [in] unsigned int offset, [in] unsigned int length, [out] unsigned int transferedLength) | 发送管道请求。此API以同步方式工作。此API适用于中断传输和批量传输。 | 33| [GetDeviceMemMapFd](#getdevicememmapfd) ([in] unsigned long deviceId, [out] FileDescriptor fd) | 获取内存映射的文件描述符。 | 34 35 36## 成员函数说明 37 38 39### ClaimInterface() 40 41``` 42IUsbDdk::ClaimInterface ([in] unsigned long deviceId, [in] unsigned char interfaceIndex, [out] unsigned long interfaceHandle ) 43``` 44**描述** 45声明USB接口。 46 47**起始版本:** 4.0 48 49**参数:** 50 51| 名称 | 描述 | 52| -------- | -------- | 53| deviceId | 要操作的设备的ID。 | 54| interfaceIndex | 接口索引,对应于USB协议中的**b接口编号**。 | 55| interfaceHandle | 接口操作处理。成功声明接口后,将为此参数分配一个值。 | 56 57**返回:** 58 590 表示操作成功。 60 61非零值 表示操作失败。 62 63 64### GetConfigDescriptor() 65 66``` 67IUsbDdk::GetConfigDescriptor ([in] unsigned long deviceId, [in] unsigned char configIndex, [out] List< unsigned char > configDesc ) 68``` 69**描述** 70获取配置描述符。 71 72**起始版本:** 4.0 73 74**参数:** 75 76| 名称 | 描述 | 77| -------- | -------- | 78| deviceId | 要获取其描述符的设备的设备Id。 | 79| configIndex | 配置索引,对应于USB协议中的**bConfigurationValue**。 | 80| configDesc | 配置描述符,包括USB协议中定义的标准配置描述符以及相关的接口描述符和端点描述符。 | 81 82**返回:** 83 840 表示操作成功。 85 86非零值 表示操作失败。 87 88 89### GetCurrentInterfaceSetting() 90 91``` 92IUsbDdk::GetCurrentInterfaceSetting ([in] unsigned long interfaceHandle, [out] unsigned char settingIndex ) 93``` 94**描述** 95获取USB接口的激活备用设置。 96 97**起始版本:** 4.0 98 99**参数:** 100 101| 名称 | 描述 | 102| -------- | -------- | 103| interfaceHandle | 接口操作处理。 | 104| settingIndex | 备用设置的索引,对应于USB协议中的**bAlternateSetting**。 | 105 106**返回:** 107 1080 表示操作成功。 109 110非零值 表示操作失败。 111 112 113### GetDeviceDescriptor() 114 115``` 116IUsbDdk::GetDeviceDescriptor ([in] unsigned long deviceId, [out] struct UsbDeviceDescriptor desc ) 117``` 118**描述** 119获取USB设备描述符。 120 121**起始版本:** 4.0 122 123**参数:** 124 125| 名称 | 描述 | 126| -------- | -------- | 127| deviceId | 要获取其描述符的设备的设备Id。 | 128| desc | USB协议中定义的标准设备描述符。 | 129 130**返回:** 131 1320 表示操作成功。 133 134非零值 表示操作失败。 135 136 137### GetDeviceMemMapFd() 138 139``` 140IUsbDdk::GetDeviceMemMapFd ([in] unsigned long deviceId, [out] FileDescriptor fd ) 141``` 142**描述** 143获取内存映射的文件描述符。 144 145**起始版本:** 4.0 146 147**参数:** 148 149| 名称 | 描述 | 150| -------- | -------- | 151| deviceId | 待操作设备的ID。 | 152| fd | 为内存映射获取的文件描述符。 | 153 154**返回:** 155 1560 表示操作成功。 157 158非零值 表示操作失败。 159 160 161### Init() 162 163``` 164IUsbDdk::Init () 165``` 166**描述** 167初始化DDK。 168 169**起始版本:** 4.0 170 171**返回:** 172 1730 表示操作成功。 174 175非零值 表示操作失败。 176 177 178### Release() 179 180``` 181IUsbDdk::Release () 182``` 183**描述** 184在停止数据传输后关闭占用的USB设备接口,并释放相关资源。 185 186**起始版本:** 4.0 187 188**返回:** 189 1900 表示操作成功。 191 192非零值 表示操作失败。 193 194 195### ReleaseInterface() 196 197``` 198IUsbDdk::ReleaseInterface ([in] unsigned long interfaceHandle) 199``` 200**描述** 201在停止数据传输后关闭占用的USB设备接口,并释放相关资源。 202 203**起始版本:** 4.0 204 205**参数:** 206 207| 名称 | 描述 | 208| -------- | -------- | 209| interfaceHandle | 接口操作处理。 | 210 211**返回:** 212 2130 表示操作成功。 214 215非零值 表示操作失败。 216 217 218### SelectInterfaceSetting() 219 220``` 221IUsbDdk::SelectInterfaceSetting ([in] unsigned long interfaceHandle, [in] unsigned char settingIndex ) 222``` 223**描述** 224激活USB接口的备用设置。 225 226**起始版本:** 4.0 227 228**参数:** 229 230| 名称 | 描述 | 231| -------- | -------- | 232| interfaceHandle | 接口操作处理。 | 233| settingIndex | 备用设置的索引,对应于USB协议中的**bAlternateSetting**。 | 234 235**返回:** 236 2370 表示操作成功。 238 239非零值 表示操作失败。 240 241 242### SendControlReadRequest() 243 244``` 245IUsbDdk::SendControlReadRequest ([in] unsigned long interfaceHandle, [in] struct UsbControlRequestSetup setup, [in] unsigned int timeout, [out] List< unsigned char > data ) 246``` 247**描述** 248发送控制读取传输请求。此API以同步方式工作。 249 250**起始版本:** 4.0 251 252**参数:** 253 254| 名称 | 描述 | 255| -------- | -------- | 256| interfaceHandle | 接口操作处理。 | 257| setup | 请求数据,对应于USB协议中的**Setup Data**。 | 258| timeout | 超时持续时间,以毫秒为单位。 | 259| data | 要传输的数据。 | 260 261**返回:** 262 2630 表示操作成功。 264 265非零值 表示操作失败。 266 267 268### SendControlWriteRequest() 269 270``` 271IUsbDdk::SendControlWriteRequest ([in] unsigned long interfaceHandle, [in] struct UsbControlRequestSetup setup, [in] unsigned int timeout, [in] List< unsigned char > data ) 272``` 273**描述** 274发送控制写入传输请求。此API以同步方式工作。 275 276**起始版本:** 4.0 277 278**参数:** 279 280| 名称 | 描述 | 281| -------- | -------- | 282| interfaceHandle | 接口操作处理。 | 283| setup | 请求数据,对应于USB协议中的**Setup Data**。 | 284| timeout | 超时持续时间,以毫秒为单位。 | 285| data | 要传输的数据。 | 286 287**返回:** 288 2890 表示操作成功。 290 291非零值 表示操作失败。 292 293 294### SendPipeRequest() 295 296``` 297IUsbDdk::SendPipeRequest ([in] struct UsbRequestPipe pipe, [in] unsigned int size, [in] unsigned int offset, [in] unsigned int length, [out] unsigned int transferedLength ) 298``` 299**描述** 300发送管道请求。此API以同步方式工作。此API适用于中断传输和批量传输。 301 302**起始版本:** 4.0 303 304**参数:** 305 306| 名称 | 描述 | 307| -------- | -------- | 308| 管道用于传输数据的管道。 | | 309| size | 缓冲区大小。 | 310| offset | 所用缓冲区的偏移量。默认值为0,表示没有偏移,缓冲区从指定地址开始。 | 311| length | 使用的缓冲区的长度。默认情况下,该值等于大小,表示使用了整个缓冲区。 | 312| transferedLength | 传输数据的长度。 | 313 314**返回:** 315 3160 表示操作成功。 317 318非零值 表示操作失败。 319